﻿using BPMN.Application.Contracts.BaseWay;
using BPMN.Application.Contracts.DTO.Request.Routing;
using BPMN.Application.Contracts.DTO.Response;
using BPMN.Application.IService;
using BPMN.Domain.Entity.Routing;
using BPMN.DomianShare;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BPMN.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoutingController : ControllerBase
    {
        private readonly IRoutingService routing;

        public RoutingController(IRoutingService routing)
        {
            this.routing = routing;
        }

        /// <summary>
        /// 添加工艺路线-工序列表信息
        /// </summary>
        /// <param name="dto">工艺路线工序关联信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddProcess(ProcessDto dto)
        {
            return Ok(await routing.AddProcess(dto));
        }

        /// <summary>
        /// 添加工艺路线信息
        /// </summary>
        /// <param name="dto">工艺路线信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddRouting(Routings dto)
        {
            return Ok(await routing.AddRouting(dto));
        }

        /// <summary>
        /// 删除工艺路线信息
        /// </summary>
        /// <param name="id">工艺路线Id</param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> DeleleRouting(int id)
        {
            return Ok(await routing.DeleleRouting(id));
        }

        /// <summary>
        /// 获取工艺路线-工序列表信息
        /// </summary>
        /// <param name="id">工艺路线Id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetProcess(int id)
        {
            return Ok(await routing.GetProcess(id));
        }

        /// <summary>
        /// 分页、显示、查询工艺路线信息
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页显示</param>
        /// <param name="code">工艺路线编码</param>
        /// <param name="name">工艺路线名称</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetRouting(int pageIndex, int pageSize, string code, string name)
        {
            return Ok(await routing.GetRouting(pageIndex, pageSize, code, name));
        }

        /// <summary>
        /// 显示工艺路线信息（用于下拉框显示）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetRoutings()
        {
            return Ok(await routing.GetRoutings());
        }

        /// <summary>
        /// 反填工艺路线信息
        /// </summary>
        /// <param name="id">工艺路线Id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetRoutingById(int id)
        {
            return Ok(await routing.GetRoutingById(id));
        }

        /// <summary>
        /// 修改工艺路线信息
        /// </summary>
        /// <param name="dto">工艺路线</param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> UpdateRouting(Routings dto)
        {
            return Ok(await routing.UpdateRouting(dto));
        }
    }
}
